package mmoon.mmoonstory.eventhandler;

import mmoon.mmoonstory.MMoonAll;
import mmoon.mmoonstory.MMoonStory;
import mmoon.mmoonstory.interfaces.HasModel;
import net.minecraft.block.Block;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.item.Item;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionType;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

@Mod.EventBusSubscriber(modid = MMoonStory.MOD_ID)
public class EventRegistry {
    @SubscribeEvent
    public static void registerItem(net.minecraftforge.event.RegistryEvent.Register<Item> event) {
        event.getRegistry().registerAll(MMoonAll.MMOON_ITEMS.toArray(new Item[]{}));
    }

    @SubscribeEvent
    public static void registerBlock(net.minecraftforge.event.RegistryEvent.Register<Block> event) {
        event.getRegistry().registerAll(MMoonAll.MMOON_BLOCKS.toArray(new Block[]{}));
    }

    @SubscribeEvent
    public static void registerEnchantment(net.minecraftforge.event.RegistryEvent.Register<Enchantment> event) {
        event.getRegistry().registerAll(MMoonAll.MMOON_ENCHANTMENTS.toArray(new Enchantment[]{}));
    }

    @SubscribeEvent
    public static void registerPotion(net.minecraftforge.event.RegistryEvent.Register<Potion> event) {
        event.getRegistry().registerAll(MMoonAll.MMOON_POTIONS.toArray(new Potion[]{}));

    }

    @SubscribeEvent
    public static void registerPotionType(net.minecraftforge.event.RegistryEvent.Register<PotionType> event) {
        event.getRegistry().registerAll(MMoonAll.MMOON_POTIONTYPES.toArray(new PotionType[]{}));
    }

    @SubscribeEvent
    public static void onModelRegistry(ModelRegistryEvent event) {
        for (Item i : MMoonAll.MMOON_ITEMS) {
            if (i instanceof HasModel) {
                ((HasModel) i).regModel();
            }
        }
        for (Block i : MMoonAll.MMOON_BLOCKS) {
            if (i instanceof HasModel) {
                ((HasModel) i).regModel();
            }
        }
    }
}
